package com.me.collector.items;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Shape;
import com.badlogic.gdx.utils.Array;
import com.me.collector.Definitions;
import com.me.collector.FallingItems;
import com.me.collector.FallingObject;
import com.me.collector.FallingObjectList;
import com.me.collector.Ground;
import com.me.collector.Hero;
import com.me.collector.Item;

public class Bomb extends Item {
	
	private Sound soundExplode;
	private ParticleEffectPool expPool;
	
	public Bomb()
	{
		super("items/bomb.png", 32, 32, 0);
		
		// Sound
		soundExplode = Gdx.audio.newSound(Gdx.files.internal("sounds/explosion.wav"));
		
		// Particle
		ParticleEffect expEffect = new ParticleEffect();
		expEffect.load(Gdx.files.internal("particles/explosionParticle.p"), Gdx.files.internal("particles"));
		expPool = new ParticleEffectPool(expEffect, 1, 2);
	}

	@Override
	public ArrayList<Shape> createShapes() {
		ArrayList<Shape> shapes = new ArrayList<Shape>();
		// circle Shape	
		CircleShape c = new CircleShape();
		c.setRadius(height * Definitions.WORLD_TO_BOX / 2f);
		c.setPosition(new Vector2(16 * Definitions.WORLD_TO_BOX, 18 * Definitions.WORLD_TO_BOX));
		
		shapes.add(c);
		
		return shapes;
	}

	@Override
	public void effect(Hero hero, FallingObject o, FallingItems fItems) {
		// TODO Auto-generated method stub
		explode(hero, o, fItems);
	}
	
	

	
	@Override
	public void impact(Hero hero, FallingObject o, FallingItems fItems, Ground ground) {
		explode(hero, o, fItems);
	}

	private void explode(Hero hero, FallingObject o, FallingItems fItems)
	{
		fItems.addEffect(expPool.obtain(), o.getPosition().x + width / 2f, o.getPosition().y);
		o.remove();
	}
}
